package com.zc.study.thread.多线程第三章节.thread3_1_1;

public class Thread2 extends Thread {
    private ThreadUtils threadUtils;
    public Thread2(ThreadUtils threadUtils) {
        this.threadUtils=threadUtils;
    }

    @Override
    public void run() {
        System.out.println("线程启动");
        super.run();
        try {
        while (true){
            if(threadUtils.getIndex()>5){
                    throw new IllegalAccessException();
            }else {
                System.out.println("线程b正在执行");
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
